#include <iostream>
#include <fstream>
#include <csignal>

#include "../../comm/httplib.h"
#include "read_server_control.hpp"

using namespace httplib;
using namespace ns_control;

void signal_handler(int signal)
{
    if (signal == SIGTERM)
    {
        std::exit(0);
    }
}

int main()
{
    std::signal(SIGTERM, signal_handler);

    Server svr;

    control ctrl;

    // 业务1. 获取小说章节
    svr.Get(R"(/read/(\d+)/(\d+))", [&ctrl](const Request &req, Response &resp)
            { 
                std::string book_id=req.matches[1];
                std::string chapter_id = req.matches[2];
                std::string html;
                ctrl.oneChapter(book_id, chapter_id, &html);
                resp.set_content(html, "text/html; charset=utf-8"); });

    svr.listen("0.0.0.0", 8081);
    return 0;
}